package com.example.userserver.controller;

import com.example.userserver.enums.ReturnEnum;
import com.example.userserver.params.BalanceParams;
import com.example.userserver.params.PageUserInfoParams;
import com.example.userserver.params.UserInfoParams;
import com.example.userserver.service.UserInfoService;
import com.example.userserver.vo.Result;
import com.example.userserver.vo.UserInfoVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user-server")
@Api(tags = "用户接口")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation(value = "获取分页用户")
    @PostMapping(value = "/pageUser")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<PageInfo<UserInfoVO>> pageGoods(@RequestBody PageUserInfoParams pageUserInfoParams) {
        return new Result(userInfoService.pageUserInfo(pageUserInfoParams), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "获取用户")
    @GetMapping(value = "/getUser")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<UserInfoVO> getUserInfo(@RequestParam String id) {
        return new Result(userInfoService.getUserInfo(id), ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "获取用户是否填写完整个人信息")
    @GetMapping(value = "/getIsComplete")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result<Boolean> getIsComplete(@RequestParam String id) {
        return userInfoService.getIsComplete(id);
    }

    @ApiOperation(value = "删除用户")
    @DeleteMapping(value = "/deleteUser")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result deleteUserInfo(@RequestParam String id) {
        userInfoService.deleteUserInfo(id);
        return new Result(null, ReturnEnum.SUCCESS);
    }

    @ApiOperation(value = "修改用户")
    @PutMapping(value = "/updateUser")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result updateUserInfo(@RequestBody UserInfoParams userInfoParams) {
        return userInfoService.updateUserInfo(userInfoParams);
    }

    @ApiOperation(value = "新增用户")
    @PostMapping(value = "/insertUser")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result insertUserInfo(@RequestBody UserInfoParams userInfoParams) {
        return userInfoService.insertUserInfo(userInfoParams);
    }

    @ApiOperation(value = "修改密码")
    @PutMapping(value = "/updatePassword")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result updatePassword(@RequestBody UserInfoParams userInfoParams) {
        return userInfoService.updatePassword(userInfoParams);
    }

    @ApiOperation(value = "修改余额")
    @PutMapping(value = "/updateBalance")
    @ApiImplicitParams({@ApiImplicitParam(name = "Authorization", required = true,
            paramType = "header")})
    public Result updateBalance(@RequestBody BalanceParams balanceParams) {
        return userInfoService.updateBalance(balanceParams);
    }

}
